home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Sample Code / QuickTime / ChromaKeyMovie / Sources / windows.c < prev   
Encoding:
Text File  |  1995-11-20  |  5.0 KB  |  206 lines  |  [TEXT/MPS ]

  1. /****************************************************/
  2. /*                                                     */
  3. /*    File:    windows.c                                 */
  4. /*                                                     */
  5. /*    Program:    ChromaKeyMovie                         */
  6. /*                                                    */
  7. /*    By:        Jason Hodges-Harris                        */
  8. /*                                                    */
  9. /*    Copyright:    © 1995 by Apple Computer, Inc.,        */ 
  10. /*                    all rights reserved.            */        
  11. /*                                                    */
  12. /****************************************************/
  13.  
  14.  
  15. // Mac Toolbox headers
  16.  
  17. #ifndef __DESK__
  18. #include <Desk.h>
  19. #endif
  20.  
  21. #ifndef __DIALOGS__
  22. #include <Dialogs.h>
  23. #endif
  24.  
  25. #ifndef __MEMORY__
  26. #include <Memory.h>
  27. #endif
  28.  
  29. #ifndef __MOVIES__
  30. #include <Movies.h>
  31. #endif
  32.  
  33. #ifndef __TEXTUTILS__
  34. #include <TextUtils.h>
  35. #endif
  36.  
  37. #ifndef __WINDOWS__
  38. #include <Windows.h>
  39. #endif
  40.  
  41.  
  42. // Program headers
  43.  
  44. #ifndef __CHROMAPPHEADER__
  45. #include "ChromaKeyMovie.app.h"
  46. #endif
  47.  
  48. #ifndef __CHROMAPROTOSHEADER__
  49. #include "ChromaKeyMovie.protos.h"
  50. #endif
  51.  
  52.  
  53. //    Global Variables
  54.  
  55. extern Boolean            gDone;
  56. extern Boolean            gMovieOpen;
  57. extern GWorldPtr        gOffscreenPort,
  58.                         gBackGroundPort,
  59.                         gBackGroundPicture;
  60. extern PixMapHandle        gMoviePixmap,
  61.                         gBackGndPixmap,
  62.                         gBackGndPictPM;
  63.  
  64.  
  65.  /* The DisplayAlert() function is a generic modal dialog display function
  66.     which uses GetStdFilterProc() and SetDialogDefaultItem() to
  67.     automatically get the standard filter and outline the default DITL item.
  68.     These 'undocumented' functions are available in system 7.0 or later. */
  69.  
  70.  #pragma segment Windows
  71. long DisplayAlert (short dialogID,short errStrID,short StrIDindex)
  72. {
  73.     GrafPtr            savePort = nil;
  74.     DialogPtr        myDialog = nil;
  75.     ModalFilterUPP    theFilter = nil;
  76.     Str255            theTextStr;
  77.     short            alertResponse;    
  78.  
  79.     myDialog = GetNewDialog(dialogID,nil,((WindowPtr)-1L));    // get dialog resource
  80.     GetPort(&savePort);
  81.     SetPort    (myDialog);
  82.     if (GetStdFilterProc(&theFilter) !=noErr)
  83.         DebugStr("\pFailed to get standard dialog filter.");
  84.     SetDialogDefaultItem(myDialog,1);
  85.     /* If the errStrID variable contains 0, the dialog doesn't
  86.        require any text from a STR# resource */
  87.     if (errStrID!=0)        // get STR# resource text
  88.     {
  89.         GetIndString(theTextStr,errStrID,StrIDindex);
  90.         ParamText(theTextStr,"\p","\p","\p");
  91.     }
  92.     do{
  93.         ModalDialog(theFilter,&alertResponse);
  94.     } while (alertResponse==0);
  95.     DisposeDialog(myDialog);//    dispose dialog mem allocation
  96.     SetPort(savePort);        
  97.     return alertResponse;    // return dialog return value
  98. }
  99.  
  100.  
  101. // Drag the window from the position passed in the mouseLoc parameter 
  102.  
  103. #pragma segment Windows
  104. void DragSelWind(WindowPtr window,Point mouseLoc)
  105. {
  106.     Rect    dragBounds;
  107.     
  108.     dragBounds=(**GetGrayRgn()).rgnBBox;
  109.     DragWindow(window,mouseLoc,&dragBounds);
  110. }
  111.  
  112.  
  113. // Close the active window which had it's close box selected
  114. #pragma segment Windows
  115. void DoGoAwayWind(WindowPtr window,Point mouseLoc)
  116. {
  117.     if(TrackGoAway(window,mouseLoc))
  118.     {
  119.         if (window!=nil)
  120.         {
  121.             // Test for a dialog window and hide if selected
  122.             if ((((WindowPeek)window)->windowKind)==2) 
  123.                 HideWindow(window);
  124.             // Test for a Desk Accessory window and Close.
  125.             else if ((((WindowPeek)window)->windowKind)<0) 
  126.                 CloseDeskAcc(((WindowPeek)window)->windowKind);
  127.             // Test for an application window.
  128.             else if ((((WindowPeek)window)->windowKind)==8)    
  129.             {
  130.                 DisposeWindowDocs (window);
  131.             }
  132.         }
  133.     }
  134. }
  135.  
  136.  
  137. // Close an application window
  138.  
  139. #pragma segment Windows
  140. void DisposeWindowDocs (WindowPtr window)
  141. {
  142.     MovieDocHndl        myRefcon;
  143.  
  144.     // check if the window to close is a valid Document window
  145.     if ((myRefcon=(MovieDocHndl)GetWRefCon(window)) ==
  146.         (MovieDocHndl)(((WindowPeek)window)->refCon))
  147.     {
  148.         // dispose of the window document structure
  149.         DisposeMovie((**myRefcon).theMovie);
  150.         DisposeHandle((Handle)myRefcon);
  151.         DisposeWindow(window);
  152.  
  153.         // Unlock and Dispose the offscreen GWorlds
  154.         if (gOffscreenPort)
  155.         {
  156.             UnlockPixels(gMoviePixmap);
  157.             UnlockPixels(gBackGndPixmap);
  158.             UnlockPixels(gBackGndPictPM);
  159.             DisposeGWorld(gOffscreenPort);
  160.             DisposeGWorld(gBackGroundPort);
  161.             DisposeGWorld(gBackGroundPicture);
  162.             gBackGroundPicture = gBackGroundPort = gOffscreenPort = nil;
  163.             DoAdjustFileMenu();
  164.         }
  165.     }
  166. }
  167.  
  168.  
  169. // Update "dirty" open window
  170.  
  171. #pragma segment Windows
  172. void    DoWindUpdate(WindowPtr theWindow)
  173. {
  174.     MovieDocHndl        myRefcon = nil;
  175.     PixMapHandle        updatePixMapH = nil;
  176.     WindowPtr            oldPort;
  177.     
  178.     GetPort(&oldPort);                // get old window port
  179.     SetPort(theWindow);                // set to port with update event request
  180.     BeginUpdate(theWindow);            // start update process
  181.      // update the current window's movie
  182.      UpdateMovie((**(MovieDocHndl)GetWRefCon(theWindow)).theMovie);
  183.     EndUpdate(theWindow);            // end update process
  184.     SetPort (oldPort);                // reset active window port
  185. }
  186.  
  187.  
  188. // Open a Movie window, allocate the document structure and place into the window's refCon field.
  189.  
  190. #pragma segment Windows
  191. CWindowPtr    OpenCWindow(void)
  192. {
  193.     CWindowPtr            theWindow;
  194.     MovieDocHndl        theDocHndl;
  195.     Rect                theRect = {0,0,100,100};
  196.     
  197.     theDocHndl = (MovieDocHndl)NewHandle(sizeof(MovieDoc));
  198.     if (theDocHndl == nil)
  199.             DisplayAlert (rGenAlert,rErrMessages,3);
  200.     else
  201.     {
  202.         theWindow = (CWindowPtr)GetNewCWindow(rGenWindow,nil,(WindowPtr)-1L);
  203.         SetWRefCon((WindowPtr)theWindow,(long)theDocHndl);    // set refcon to doc handle
  204.     }
  205.     return theWindow;
  206. }